package chapter06

/**
 * 封装
 * 构造参数
 */
object Test07_Inherit {
  def main(args: Array[String]): Unit = {
    val student1 = new Student4("alice", 18)
    student1.printInfo()
    val student2 = new Student4("bob", 18, "std001")
    student2.printInfo()
  }


}

//定义一个父类
class Person3() {
  var name: String = _
  var age: Int = _


  println("1、父类的主构造器调用")

  def this(name: String, age: Int) {
    this()
    println("2、父类的辅助构造器调用")
    this.name = name
    this.age = age
  }

  def printInfo(): Unit = {
    println(s"Person: $name $age")
  }
}

//子类继承父类--------extends Person3(name,age) 相当于父类的构造器调用、写那个调那个
class Student4(name: String, age: Int) extends Person3(name, age) {
  var stdNo: String = _

  println("3、子类的主构造方法器调用")

  def this(name: String, age: Int, stdNo: String) {
    this(name: String, age: Int)
    println("4、子类的辅助构造器调用")
    this.stdNo = stdNo
  }

  override def printInfo(): Unit = {
    println(s"Person: $name $age $stdNo")
  }
}
